package com.augrain.microframework.lock.annotation;

import com.augrain.microframework.lock.model.LockType;
import com.augrain.microframework.lock.strategy.LockTimeoutFastFailStrategy;
import com.augrain.microframework.lock.strategy.LockTimeoutStrategy;
import com.augrain.microframework.lock.strategy.ReleaseTimeoutFastFailStrategy;

import java.lang.annotation.*;

/**
 * 锁注解
 *
 * @author biaoy
 * @since 2021/06/10
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface DLock {
    /**
     * 锁的名称
     *
     * @return name
     */
    String name() default "";

    /**
     * 锁类型，默认可重入锁
     *
     * @return lockType
     */
    LockType lockType() default LockType.REENTRANT;

    /**
     * 尝试加锁，最多等待时间
     *
     * @return waitTime
     */
    long waitTime() default Long.MIN_VALUE;

    /**
     * 上锁以后xxx秒自动解锁
     *
     * @return leaseTime
     */
    long leaseTime() default Long.MIN_VALUE;

    /**
     * 自定义业务key
     *
     * @return keys
     */
    String[] keys() default {};

    /**
     * 加锁超时的处理策略
     *
     * @return lockTimeoutStrategy
     */
    Class<? extends LockTimeoutStrategy> lockTimeoutStrategy() default LockTimeoutFastFailStrategy.class;

    String customLockTimeoutStrategy() default "";

    /**
     * 释放锁时已超时的处理策略
     *
     * @return releaseTimeoutStrategy
     */
    Class<? extends ReleaseTimeoutFastFailStrategy> releaseTimeoutStrategy() default ReleaseTimeoutFastFailStrategy.class;

}
